package com.bookmanagement.controller.admin;

import com.bookmanagement.VO.AdminUserVO;
import com.bookmanagement.result.Result;
import com.bookmanagement.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 管理端用户管理Controller
 * @author skyjay
 */
@RestController
@RequestMapping("/admin/user")
public class AdminUserController {

    @Autowired
    private UserService userService;

    /**
     * 获取所有用户（无论状态）
     */
    @GetMapping("/list")
    public Result<List<AdminUserVO>> getAllUsers() {
        List<AdminUserVO> users = userService.getAllUsers();
        return Result.success(users);
    }

    /**
     * 切换用户状态（禁用/启用）
     */
    @PutMapping("/status/{userId}")
    public Result toggleUserStatus(@PathVariable("userId") Integer userId) {
        userService.toggleUserStatus(userId);
        return Result.success();
    }

    /**
     * 重置用户密码为123456
     */
    @PutMapping("/reset-password/{userId}")
    public Result resetUserPassword(@PathVariable("userId") Integer userId) {
        userService.resetUserPassword(userId);
        return Result.success();
    }
}
